from itsdangerous import TimedJSONWebSignatureSerializer as TJWSS
from django.conf import settings


def dumps(data, ex_time):
    s = TJWSS(secret_key=settings.SECRET_KEY, expires_in=ex_time)
    token = s.dumps(data).decode()
    return token


def loads(token, ex_time):
    s = TJWSS(secret_key=settings.SECRET_KEY, expires_in=ex_time)
    data = s.loads(token)
    return data
